<!--
 * @Author: giteezr 2250368646@qq.com
 * @Date: 2024-02-27 09:29:16
 * @LastEditors: giteezr 2250368646@qq.com
 * @LastEditTime: 2024-03-01 09:52:33
 * @FilePath: \vue3+nodeJs\houtaiguanli\management-system\src\views\sweepercar\global\components\popups\workcalculate.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <!-- 台班计量 -->
  <div class="workcalculate">
    <div ref="dom" class="dome"></div>
  </div>
</template>
<script  setup lang="ts">
import * as echarts from "echarts";
import { ref, watch, nextTick, reactive, onMounted } from "vue";
// 接收值
let props = defineProps({
  carData: {
    type: Object,
    default: false,
  },
});
let data = reactive({
  teamData: {  roadName: [], workhours: []},
  index:[]
});
let { teamData,index } = data;
// 定义值
let dom = ref(); //ref的应用
// 定义加载函数
let initCharts = () => {
  let chart = echarts.init(dom.value);
  const option =  {
        tooltip: {
          axisPointer: {
            type: 'shadow'
          },
          trigger: 'axis',
          textStyle: {
            align: 'left'
          }
        },
        toolbox: {
          show: true,
          feature: {
            saveAsImage: {}
          }
        },
        legend: {
          itemWidth: 20,
          itemHeight: 10,
          textStyle: {
            color: '#90D4F8',
            align: 'left'
          }
        },
        grid: {
          top: '15%',
          left: '5%',
          right: '5%',
          bottom: '10%',
          containLabel: true
        },
        dataZoom: [
          {
            type: 'inside',
            xAxisIndex: 0
          },
          {
            show: true,
            type: 'slider',
            xAxisIndex: 0,
            textStyle: {
              color: '#26FFFF'
            },
            backgroundColor: '#074468',
            dataBackground: {
              lineStyle: {
                color: '#597F97'
              }, // 阴影的线条样式
              areaStyle: {
                color: '#597F97'
              } // 阴影的填充样式
            },
            borderColor: '#046291',
            top: '95%',
            start: 98,
            end: 100
          }
        ],
        xAxis: {
          type: 'category',
          name: '台班数',
          data: index,
          axisLabel: {
            show: true,
            // interval: 0,
            // rotate: 1,
            align: 'center',
            margin: 15,
            textStyle: {
              color: '#90D4F8'
            }
          },
          axisLine: {
            show: false,
            interval: 0,
            lineStyle: {
              color: '#468C9E',
              type: 'solid'
            }
          },
          axisTick: {
            show: false
          },
          splitLine: {
            show: false,
            lineStyle: {
              color: '#213862',
              width: 1,
              type: 'solid'
            }
          }
        },
        yAxis: [
          {
            type: 'value',
            name: '时长(分钟)',
            splitLine: {
              show: true,
              lineStyle: {
                color: '#213862',
                width: 1,
                type: 'solid'
              }
            },
            axisLine: {
              show: true,
              interval: 0,
              lineStyle: {
                color: '#468C9E',
                type: 'solid'
              }
            },
            axisLabel: {
              show: true,
              textStyle: {
                color: '#90D4F8'
              }
            },
            axisTick: {
              show: false
            }
          }
        ],
        series: teamData.workhours
      };
  chart.setOption(option, true);
  // 当窗口大小改变时候，echarts重置大小
  window.addEventListener("resize", () => {
    chart.resize();
  });
};
onMounted(() => {
  nextTick(() => {
    initCharts();
  });
});
// 监听当配置项发生变化的时候，调用加载函数
watch(
  () => props.carData,
  (val) => {
    if (Object.keys(val)) {
      nextTick(() => {
        // initCharts();
      });
    }
  },
  { immediate: true }
);
</script>
<style scoped>
.dome,
.workcalculate {
  width: 100%;
  height: 100%;
}
</style>